/**
 * 打开弹出窗口
 **/
function openWindow(url_, title_, width_, height_){
	$('#popupWin').remove();
	$(document.body).append('<div id="popupWin"></div>');
	
	if(title_ == undefined) title_ = '弹出窗口';
	var winSetting = {
		title: title_,
		collapsible: false,
		minimizable: false,
		maximizable: true,
	    modal: true,
	    content: '<iframe id="innerWin" frameborder="0" width="100%" height="100%" scrolling="auto" src="' + url_ + '"></iframe>'
	};
	
	var maximized = false;
	if(typeof width_ == 'undefined' || typeof height_ == 'undefined'){
		maximized = true;
	}
	if(maximized){
		//winSetting.maximized = true;
		winSetting.width = window.screen.width - 200;
		winSetting.height = window.screen.height - 350;
	}else{
		winSetting.width = width_;
		winSetting.height = height_;
	}

	$('#popupWin').window(winSetting);
}

/**
 * 关闭弹出窗口
 */
function closeWindow(){
	window.parent.$('#popupWin').window('close');
}
	
/**
* 弹出模态窗口
* url: 弹出窗口内容url
* opener: 弹出窗口的父窗口引用 
* sizeMode: 弹出窗口大小模式 full/medium/small/custom
* 		full: 表示弹出全屏窗口
* 		medium: 表示弹出中型窗口
* 		full: 表示弹出小型窗口
* 		custom: 表示弹出自定义大小的窗口
*/
function openModalWindow(url, opener, sizeMode, width, height){
	var configs = 'center:yes; help:no; status:yes; scroll:yes; resizable:no;';
	var width_ = 650, height_ = 500;
	if(sizeMode == 'full'){
		width_ = window.screen.availWidth;
		height_ = window.screen.availHeight;
	}else if(sizeMode == 'medium'){
		width_ = window.screen.width - 300;
		height_ = window.screen.height - 200;
	}else if(sizeMode == 'small'){
		width_ = 300;
		height_ = 500;
	}else if(sizeMode == 'custom'){
		width_ = width;
		height_ = height;
	}
	configs += 'dialogWidth=' + width_ + 'px; ';
	configs += 'dialogHeight=' + height_ + 'px; ';
	return showModalDialog(url, opener, configs);
}

/*-----------------------获取对象,checkbox 全选/删除/修改-----------------------*/
function getobj(objtag, objname) {
	var obj = document.getElementsByTagName(objtag);
	var arrobj = new Array();
	var j = 0;
	for (var i = 0; i < obj.length; i++) { 
        //if(obj[i].name.indexOf(objname)>=0){
		if (obj[i].name != undefined && obj[i].name.length >= objname.length && obj[i].name.substring(0, objname.length) == objname) {
			arrobj[j] = obj[i];
			j = j + 1;
		}
	}
	return arrobj;
}
	
//初始化数据表格样式	  
function initTableGrid(){
	Ptr=document.getElementById("tab").getElementsByTagName("tr");
    for (var i=1; i<Ptr.length+1; i++){ 
    	Ptr[i-1].style.backgroundColor = (i%2>0)?"#fff":"#eef2ea"; 
    }
    for(var i=0; i<Ptr.length; i++) {
	    Ptr[i].onmouseover=function(){
		    this.tmpClass=this.className;
		    this.style.backgroundColor = "#e3f8fc";
	    };
	    Ptr[i].onmouseout=function(){
		    for (i=1;i<Ptr.length+1;i++) { 
		    	Ptr[i-1].style.backgroundColor = (i%2>0)?"#fff":"#eef2ea"; 
		    }
		};
	}
}

//获取客户端当前时间
function getCurrentTime(){
	return (new Date()).getTime();
}

//字符串为空判断
function isEmpty(str){
	if(str == null || str == undefined || str.length == 0){
		return true;
	}
	return false;
}

//获取编辑器Fck中内容
function getFckText(instanceName) {
    var oEditor = FCKeditorAPI.GetInstance(instanceName);
    return oEditor.GetXHTML();
};


//设置编辑器Fck中内容
function setFckText(instanceName, text) {
    var oEditor = FCKeditorAPI.GetInstance(instanceName) ;
    oEditor.SetHTML(text) ;
}

//判断指定年份是否为闰年
function isLeapYear(year){
	return !!((year & 3) == 0 && (year % 100 || (year % 400 == 0 && year)));
}

//获取指定月份的天数
function daysOfMonth(year, month){
	if(month == 1 || month==3 || month==5 ||month==7 ||month==8 ||month==10 ||month==12){
		return 31;
	}
	if(month == 4 || month==6 || month==9 ||month==11){
		return 30;
	}
	if(month == 2 && isLeapYear(year)){
		return 29;
	}
	if(month == 2 && !isLeapYear(year)){
		return 28;
	}
	return 0;
}

//判断数组是否包含了指定的元素
function contains(arr, ele){
	var result = false;
	for(var i=0; i<arr.length; i++){
		if(arr[i] == ele){
			result = true;
			break;
		}
	}
	return result;
}

//全选checkbox
function selectAll() {
	var arrobj = getobj("input", "chk");
	for (var i = 0; i < arrobj.length; i++) {
		if (arrobj[i].disabled == false && arrobj[i].checked == false) {
			arrobj[i].checked = true;
		} else {
			arrobj[i].checked = false;
		}
	}
}

//删除多个
function del(url) {
	var arrobj = getobj("input", "chk");
	var sltid = "";
	for (var i = 0; i < arrobj.length; i++) {
		if (arrobj[i].checked == true) {
			sltid = sltid + arrobj[i].value + ",";
		}
	}
	if (sltid == "") {
		alert("没有选择删除项！");
		return;
	} else if (sltid != "") {
		sltid = sltid.substring(0, sltid.length - 1);
		if(confirm("此操作不可恢复，确定删除吗？")){
			document.location.href = url + "?idStr=" + sltid;
		}
	}
}
//删除一个
function deleteById(id, url){
	var obj = document.getElementById(id);
	obj.checked = true;
	del(url);
}
//编辑
function edit(id, url){
	document.location.href = url + "?role.id=" + id;
}
function G(id){
	return document.getElementById(id);   
}

//去左空格
function ltrim(s)  
{  
	return s.replace(/^\s*/, "");  
}  
//去右空格
function rtrim(s)  
{  
	return s.replace(/\s*$/, "");  
}
//去掉左右空格
function trim(s) {
    return rtrim(ltrim(s));
}
//返回
function back(){
	window.history.back();
}
/*--------------------------------------end---------------------*/
//------------------添加附件 参数:1、返回表单元素ID 2、附件业务类型
function openfileupload(backid,filetype){
	var returnvalue='';
	returnvalue = window.showModalDialog("<%=basePath %>admin/public/upfile.jsp?time="+new Date() ,'附件上传', 'dialogWidth:450px; dialogHeight:200px; status:0; resizable:yes;');
	if(returnvalue!=undefined){
		//document.getElementById(backid).innerHTML=document.getElementById(backid).innerHTML+returnvalue;
		$("#"+backid).html($("#"+backid).html()+returnvalue);
	}
}
//-----------------附件 删除一行---------------
function deltr(obj){
	$(obj).parent().parent().remove();
}
/*--------------------------------------end---------------------*/